import Vue from "vue";
import VueRouter from "vue-router";

//登录
import Login from '@/views/login';
//注册
import Register from '@/views/register'
//Home
import Home from '@/views/home'
//商品管理
import goodsMgr from '@/views/goodsMgr'
//用户管理
import usersMgr from '@/views/usersMgr'
// 订单管理
import ordersMgr from '@/views/ordersMgr'

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/login",
    name: "login",
    component: Login,
    meta: {
      permission: false
    }
  },
  {
    path: "/register",
    name: "register",
    component: Register,
    meta: {
      permission: false
    }
  },
  {
    path: "/home",
    name: "home",
    redirect: "/home/users",
    component: Home,
    children: [
      {
        path: "goods",
        name: "goods",
        component: goodsMgr
      },
      {
        path: "users",
        name: "users",
        component: usersMgr
      },
      {
        path: "orders",
        name: "orders",
        component: ordersMgr
      }
    ]
  }
];

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  linkActiveClass: "active",
  routes
});

export default router;
